import React, { Component } from 'react'
import {withRouter} from 'react-router-dom'
import style from '../components/list.module.css'
const stateObj={
  "onsale": "在售",
  "forsale": "待售",
  "soldout": "售完"
}

export class List extends Component {
  render() {
    const {list} = this.props
    return (
      <div>
        {
            list.length?list.map((item)=>{
                return <dl key={item.id} onClick={()=>{this.props.history.push('/detail/'+item.id)}}>
                    <dt><img src={item.img} alt="" /></dt>
                    <dd>
                        <h4>{item.title}</h4>
                        <p>{item.price}</p>
                        <button className={style[item.state]}>{stateObj[item.state]}</button>
                    </dd>
                </dl>
            })
            :"暂无数据"
        }
      </div>
    )
  }
}

export default withRouter(List)